home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / HARDWARE / MLH20.ZIP / MLH20.TXT
Text File  |  1995-08-20  |  10KB  |  163 lines

  1. MiniSport Laptop Hacker - Vol #20.  Feb 1994 
  2. To discourage pecuniary interests, Copyright (c)1994 Brian Mork 
  3.  
  4. >>> ADMIN 
  5. Two places are archiving the MLHacker series (Thank you both!).  The 
  6. first is an Internet e-mail server: ham-server@grafex.cupertino.ca.us, 
  7. in directory \hamradio\newsletters. The second is an ftp only site: 
  8. ftp.cs.buffalo.ed, in directory \pub\msdos\ham-radio.  In either case, 
  9. look for the file mlhacker.zip.  I think my inbound mail was being re- 
  10. jected on Internet during the month of January.  Things appear to be 
  11. again stable in the Spokane area.  Notice my packet address changed. 
  12.  
  13. >>> GDU UTILITY 
  14. The GDU utility provided on your ROM disk C: is worth having!  I down- 
  15. loaded it to my main computer (use FWL and the cable described in 
  16. MLHacker #4) and tried running it there.  It works great, even with a 
  17. huge IDE disk drive! I've learned a lot about File Allocation Tables, 
  18. disk space allocation, deleted files, etc.  I thought it might be fun to 
  19. use GDU to walk through a short tour of your RAMdisk FAT.  If you mess 
  20. it up, so what?  It's RAMdisk anyway.  Clear it out and reformat it. 
  21. Takes about 45 seconds.  Do be sure to first offload important stuff 
  22. onto 2" disk or to another computer over the serial link (with FWL). 
  23.  
  24. Here's the plan.  1) We'll make a normal text file taking up two alloca- 
  25. tion units.  2) Then use GDU to make another directory entry pointing to 
  26. the same text.  CHKDSK will report this as a "cross linked" file. 
  27. 3) Then we'll delete one of the files, causing MSDOS to change the entry 
  28. for each allocation unit of that file in the FAT to available status. 
  29. CHKDSK will now report the remaining directory entry as having invalid 
  30. allocation units.  4) We'll go in and manually retake the allocations 
  31. and CHKDSK will then report a "lost allocation."  5) Finally, we'll 
  32. tweak the directory entry to point back to the recovered clusters. 
  33.  
  34. 1. From the root directory, run the MSDOS DEBUG program and get the "-" 
  35. prompt.  Enter the command "F 0100,08F7 20 48 49 0D 0A".  This puts 408 
  36. repeats of " HI<CR><LF>" into memory starting at address 0100.  A total 
  37. of 2040 (07f8 hex) bytes were stored.  For reasons that will be clear in 
  38. a moment, write out these 07f8H bytes, plus one extra, to a disk file 
  39. called HI.TXT.  Use these DEBUG commands: R CX, 07F9, N HI.TXT, W, Q. 
  40.  
  41. Type out HI.TXT and watch all the HIs scroll by on the screen.  You'll 
  42. probably have a few scrap characters at the end.  That's because DOS 
  43. only stores files in chunks of 1024 bytes on this computer.  For other, 
  44. bigger, disk drives, DOS uses bigger chunks, or clusters.  My 250 Mb 
  45. hard drive on another computer uses 4096 byte units.  Run GDU and select 
  46. the "Display FAT Cluster Chain" option.  Highlight HI2.TXT and press 
  47. return.  You'll be shown two cluster numbers where your text has been 
  48. stored.  For me, it's cluster numbers 7 and 8.  Yours will be different. 
  49. Write down *your* numbers for future use.  Whenever I refer to cluster 7 
  50. and 8 below, use your numbers instead. 
  51.  
  52. Press ESC (back to the main menu) and select the "List/Edit in Hex and 
  53. ASCII" option and select the HI.TXT file.  You'll be shown a binary im- 
  54. age of the file, plus an ASCII interpretation (try toggling the F2 key). 
  55. Scroll down to the end of the file and see the blinking cursor.  The 
  56. cursor blinks at the first byte that does *not* belong to the file. 
  57. Remember that extra byte I mentioned above?  MSDOS uses 1A (control-Z) 
  58. to mark the end of the file, and we'll replace that extra byte we saved 
  59. with a control-Z. Use the F8 key to edit the file, move over to the last 
  60. byte of the file (after the last 0D 0A, just before the previously 
  61. blinking cursor) and put a 1A in that spot.  Press F8 again to save the 
  62. changes and exit the GDU program.  Type out the file again and it will 
  63. cleanly end after the 408th "HI". 
  64.  
  65. 2. The sectors on the disk are used as follows: 
  66.  
  67.            Description        RAMdisk             2" disk 
  68.           ------------------------------------------------ 
  69.            Boot sector         0                   0 
  70.            FAT copy #1         1-5                 1-3 
  71.            FAT copy #2         6-10                4-6 
  72.            Root directory      11-42               7-13 
  73.            Clusters            43+                 14+ 
  74.  
  75. We need to go into the root directory and make a clone of HI.TXT with a 
  76. slightly different name, pointing to the same data.  First, make a nor- 
  77. mal copy with the command "COPY HI.TXT HI2.TXT", then delete it with 
  78. "DEL HI2.TXT".  Use GDU to select the "Display/Edit Logical Sectors" 
  79. option.  Choose sector 11 and scroll down until you see the HI.TXT entry 
  80. in the root directory.  Each entry takes two lines (32 bytes) on this 
  81. display.  Look further down the table of files to find rI2.TXT.  Use the 
  82. F8 key to change the E5 back to a 48 (letter H).  You just unerased 
  83. HI2.TXT, but we need to do more.  Our goal is to make it point to the 
  84. same text.  The last four bytes of a directory entry give the file size. 
  85. Both files should say 00 00 07 F9 (read backwards).  The two bytes *be- 
  86. fore* these bytes gives the first cluster that the file uses.  Mine says 
  87. 00 07 and 00 09.  Yours will be different depending on where MSDOS de- 
  88. cided to put your file at (HI.TXT should match the numbers you wrote 
  89. down above).  Use F8 to edit the HI2.TXT entry to match the HI.TXT en- 
  90. try. Run CHKDSK.  CHKDSK will report a cross link on cluster 7. 
  91.  
  92. 3. Delete HI.TXT from disk using the command "DEL HI.TXT".  CHKDSK now 
  93. reports that the first cluster number of HI2.TXT is invalid.  Why? 
  94. Cluster 7 and 8 was marked as available (000 hex for both clusters) when 
  95. MSDOS deleted HI.TXT.  When CHKDSK now looks to find the first cluster 
  96. of HI2.TXT, it finds a 000 indicating that data is in cluster zero. 
  97. Well there is no cluster zero (they range from 2-55B on the RAMdisk)! 
  98. That's why MSDOS uses 000 to indicate a deleted, available cluster.  An 
  99. unerased file points to a deleted cluster.  That's why CHKDSK says the 
  100. 000 entry at cluster 7 is invalid. 
  101.  
  102. Run CHKDSK with the /F option.  It will "fix" this problem.  What it 
  103. actually does is sets the first cluster number and size of HI2.TXT to 
  104. zero.  Problem fixed? Yea, sure, but your data is still out there on 
  105. disk, unclaimed by any file! 
  106.  
  107. 4. We need to go into the FAT and make cluster 7 point to cluster 8, and 
  108. change cluster 8 to "last cluster" status.  But where are the 12-bit FAT 
  109. entries for cluster 7 and 8?  Two formulas give the answer: 
  110.  
  111.           byte_offset = cluster# * 1.5 
  112.           FAT_Sector_offset = int ( byte_offset / 384 ) 
  113.           Offset_into_sector = byte_offset - FAT_Sector_offset * 384 
  114.  
  115. [As a quick aside, because of the limited size of the RAMdisk and the 2" 
  116. disk, MSDOS uses 1.5 bytes for a FAT entry.  If you use GDU on your main 
  117. computer with larger disks, each entry takes an even 2 bytes, making the 
  118. calculations much easier.  In that case use 2 instead of 1.5 and 256 
  119. instead of 384, in the above formulas.] 
  120.  
  121. My FAT_Sector_offset is zero for both clusters, and my Offset_into_sec- 
  122. tor comes out to 10.5 and 12.  Use your numbers as we progress.  Use GDU 
  123. to edit the (FAT_Sector_offset + 1) sector.  For me, it's sector 1.  My 
  124. bytes line up as follows: 
  125.  
  126. Byte offset into sector >     ...16 15 14 13 12 11 10 09 08 ... 
  127. Data on disk >                ...00 00 00 00 00 00 0F FF 00 ... 
  128.                                            ^^^^ ^^^^ 
  129. Cluster entry >                              8    7 
  130.  
  131. The goal is to make the first entry point to the second and put FFF into 
  132. the second one.  In my case, I'll change them as shown below.  Notice 
  133. your two cluster numbers may not be sequential.  Just go to each one 
  134. individually and fix it. 
  135.  
  136. Byte offset into sector >     ...16 15 14 13 12 11 10 09 08 ... 
  137. Data on disk >                ...00 00 00 0F FF 00 8F FF 00 ... 
  138.                                            ^^^^ ^^^^ 
  139. Cluster entry >                              8    7 
  140.  
  141. 5. CHKDSK will report "2 lost clusters in 1 chain".  Use GDU to edit the 
  142. root directory entry for HI2.TXT.  Point to the proper first cluster by 
  143. changing the 11th and 12th byte on the second line of the directory en- 
  144. try to 07 00 (or whatever your first cluster number was).  Everything is 
  145. almost back to normal.  Remember the second FAT stored in sectors 6-10 
  146. for the RAMdisk?  They don't match.  You could go manually fix them, but 
  147. there's an easier way.  Run CHKDSK.  This time it will say errors are 
  148. found, but it doesn't say that it's mismatched FATs and bad file size 
  149. entries in the directory.  Run CHKDSK with the /F option and it will fix 
  150. up the second FAT copy to match the first and will update the size of 
  151. HI2.TXT to 2048 bytes (2 clusters).  Remember the original HI.TXT was 
  152. only 2041 bytes.  You can go edit change the last four bytes in the di- 
  153. rectory entry from 00 08 00 00 to F9 07 00 00, if you wish. 
  154.  
  155. Whew!  What fun.  If it's any consolation, it took five disk drive 
  156. crashes and *days* of time for me to learn what I just related to you. 
  157. GDU is a great program and works fine on my other computer system. 
  158.  
  159. Please provide feedback!      * Direct data 1-509-244-9260 
  160.                               * AX.25 KA9SNF@wb7nnf.#ewa.wa.usa 
  161.                               * Internet bmork@opus-ovh.spk.wa.us 
  162. 73, Brian                     * 6006-B Eaker, Fairchild, WA 99011 
  163.